import java.util.Arrays;

public class Kuaipai {

    public static void main(String[] args) {
        int arr[]={1,2,34,5,8,65};
        System.out.println(Arrays.toString(arr));
        quick(0,arr.length-1,arr);
        System.out.println(Arrays.toString(arr));
    }
    public static void quick(int left,int right,int[] arr) {
        if(left<right){
            int l = left;
            int r = right;
            int flag = left;
            while (left < right) {
                while ((arr[right] > arr[flag]) && left < right) {
                    right--;
                }
                while (arr[left] < arr[flag] && left < right) {
                    left++;
                }
                if (left != right) {
                    int c = arr[left];
                    arr[left] = arr[right];
                    arr[right] = c;
                } else {
                    int c = arr[left];
                    arr[left] = arr[flag];
                    arr[flag] = c;
                }
            }
            quick(l, left - 1, arr);
            quick(left + 1, r, arr);
        }
    }
}
